package com.sasken.pdb.models.data
{
	import com.sasken.pdb.models.settings.ApplicationSettings;
	
	import mx.formatters.DateFormatter;
	
	[Bindable]
    [RemoteClass(alias="com.sasken.pdb.models.data.ScheduleItem")]

	/**
	 *  This class is a schedule item model used to convey information about 
	 *  schedule units for employees. Its length is arbitrary and measured in milliseconds.
	 *  The workload determines the color of the item, title determines the text shown in it
	 *  and the length in days is translated to pixel length on screen, depending on used time scale. 
	*/
	public class ScheduleItem extends DBTObject
	{
		 
		public var startDate:Date;
		public var endDate:Date;
		
		/** 
		 * The title of this item, if any.
		 */
		private var _title:String;
		
		
		/**
		 *  Constructor, initializes this object.
		 * 
		*/
		public function ScheduleItem()
		{
			super();
			// What is default start and end date?
		}

		[Transient]
		public function get formattedStartDate():String
		{
			var df:DateFormatter = new DateFormatter();
			df.formatString = ApplicationSettings.DATE_FORMAT;
			
			return df.format(startDate);
		}
		
		[Transient]
		public function get formattedEndDate():String
		{
			var df:DateFormatter = new DateFormatter();
			df.formatString = ApplicationSettings.DATE_FORMAT;
			
			return df.format(endDate);
		}
		
		public function set formattedStartDate(value:String):void
		{
			// empty
		}
		
		public function set formattedEndDate(value:String):void
		{
			// empty
		}
		
		public function set label(newTitle:String):void
		{
			_title = newTitle;
		}
		
		public function get label():String
		{
			return load + "%";
		}
		
		public function set load(newWorkload:int):void
		{
			/* Ignore this now (child classes will do this)
			_workload = newWorkload;
			label = _workload + "%";
			*/
		}
		
		public function get load():int
		{
			// Only children will have values
			return 0;
		}
		
		public function get backgroundColor():Number
		{
			return ApplicationSettings.getPercentageColor(load);
		}
	}
}